<?php

namespace App\Extensions\Renderable;

use App\Patent;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Show;
use Encore\Admin\Widgets\Tab;
use Illuminate\Contracts\Support\Renderable;

class PatentDetailRenderAble implements Renderable
{
    public function render($key = '')
    {
        $patent = Patent::query()->find($key);
        $tab = new Tab();
        $tab->add('基本信息', Admin::show($patent, function (Show $show) use ($patent) {
            $show->panel()->view('show.tab-panel');
            $show->field('patent_sn', __('Patent sn'));
            $show->field('patent_name', __('Patent name'));
            $show->field('patent_type_id', __('专利类型'))->using(patent_type_select_option());
            $show->field('department.name', __('department name'));
            $show->field('applicant', __('申请人'));
            $show->field('inventor', __('Inventor'));
            $show->field('apply_date', __('Apply date'));
            $show->field('legal_status', __('legal_status'));
            if ($model = $patent->apply) {
                $show->field('apply.charge_person', __('专利负责人'));
                $show->field('department.name', __('dept_name'));
                $show->field('apply.contact_person', __('联系人'));
                $show->field('apply.phone', __('联系电话'));
                $show->field('apply.other_applicant', __('合作申请单位'));
                if ($model['patent_type_id'] == 4) {
                    $show->field('other_patent_sn', __('国内申请号'));
                } elseif ($model['patent_type_id'] == 5) {
                    $show->field('apply.country', __('国家'));
                    $show->field('apply.apply_channel', __('途径'));
                    $show->field('apply.other_patent_sn', __('申请号'));
                }
            }
        }));
        $unpaids = $patent->unpaid();
        $paids = $patent->paid();
        if ($unpaids->first() || $paids->first()) {
            $tab->add('缴费信息', view('modal.patent-fee')->with(compact('patent', 'unpaids', 'paids')));
        }
        if ($patent->user) {
            $tab->add('负责人', Admin::show($patent->user, function (Show $show) {
                $show->panel()->view('show.tab-panel');
                $show->field('name', __('姓名'));
                $show->field('mobile', __('电话'));
                $show->field('email', __('邮箱'));
            }));
        }
        return $tab->render();
    }


}
